Ext.ns('CRM.commons');


(function(){
	
	/*This Method is used to create dynamic store */

		CRM.commons.createStore=function (storeid,fieldsArray,url){
			var store=new Ext.data.JsonStore({
				id:storeid,
				root:'data',
				autoLoad:true,
				fields:fieldsArray,
				proxy : new Ext.data.HttpProxy({
					method: "GET",
					url : url
					
				}),
				autoLoad : true,
				remoteSort : true
			});
		  return store;	
		},
		
		/*This method is used to create stores for combo boxes */
		
		CRM.commons.createComboStore=function(storedid,actionurl,method){
        
				if(method!=undefined || method!=null){
					actionurl=actionurl+"?operation="+method;
				}else{
					actionurl=actionurl;
				}
			
			
			var comboboxStore = new Ext.data.JsonStore({
				id:storedid,
				
				root          : 'data',
				fields     : [
								{
							    name    : 'name',
							    mapping : 'fieldValue'
								},
								{
							    name    : 'id',
							    mapping : 'id'
								},
								{
								name    : 'criteria',
								mapping : 'value'
								}
							  ],
				proxy : new Ext.data.HttpProxy({
					method: 'GET',
					url	  : actionurl
					
				}),
				remoteSort : false
			}); 
				return comboboxStore;
			
		};
		var selModel = new Ext.grid.RowSelectionModel({singleSelect : true});
		
		CRM.commons.createGrid=function(gridid,datastore,cmodel){
			
			var grid= new Ext.grid.GridPanel({
				id 			:gridid,
				height		: 180,
				frame		: true,
				store 		: datastore,
				colModel 	: cmodel,		
				selModel	: selModel,
				stripeRows	: true,
				enableRowBody : true,
				scrollable	:true,
				enableColumnResize:true,
				defaults:{align:'center'},
				sm: new Ext.grid.RowSelectionModel({singleSelect : true}),
		        listeners: {
		        			  viewready: function(g) {
		              								 g.getSelectionModel().selectRow(0);
		          									 }
	     	 				}
				
			});
			return grid;
		};		
		
		
})();